package org.jeecg.modules.wuda.app.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.wuda.entity.WudaWeatherStation;
import org.jeecg.modules.wuda.service.IWudaWeatherStationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
* @Description: App气象站气象信息表
* @Author: Wjl
* @Date:   2022-03-01
* @Version: V1.0
*/
@Api(tags="气象站气象信息表")
@RestController
@RequestMapping("/app/wuda/wudaWeatherStation")
@Slf4j
public class AppWudaWeatherStationController extends JeecgController<WudaWeatherStation, IWudaWeatherStationService> {
   @Autowired
   private IWudaWeatherStationService wudaWeatherStationService;
    /**
     * 添加用来控制app端是否能访问
     *

     * @return
     */
    @RequiresPermissions({"wudaWeatherStation"})
    @PostMapping(value = "/toAdd")
    public Result toAdd() {
        return Result.OK("true");
    }

   /**
    * 分页列表查询
    *

    * @return
    */
   @RequiresPermissions({"wudaWeatherStation"})
   //@AutoLog(value = "气象站气象信息表-分页列表查询")
   @ApiOperation(value="气象站气象信息表-分页列表查询", notes="气象站气象信息表-分页列表查询")
   @GetMapping(value = "/list")
   public Result queryPageList() {
       List<WudaWeatherStation> list = wudaWeatherStationService.list();
       return Result.OK(list);
   }

   /**
    *   添加
    *
    * @param wudaWeatherStation
    * @return
    */
   @AutoLog(value = "气象站气象信息表-添加")
   @ApiOperation(value="气象站气象信息表-添加", notes="气象站气象信息表-添加")
   @PostMapping(value = "/add")
   public Result<String> add(@RequestBody WudaWeatherStation wudaWeatherStation) {
       wudaWeatherStationService.save(wudaWeatherStation);
       return Result.OK("添加成功！");
   }

   /**
    *  编辑
    *
    * @param wudaWeatherStation
    * @return
    */
   @AutoLog(value = "气象站气象信息表-编辑")
   @ApiOperation(value="气象站气象信息表-编辑", notes="气象站气象信息表-编辑")
   @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
   public Result<String> edit(@RequestBody WudaWeatherStation wudaWeatherStation) {
       System.out.println(wudaWeatherStation);
       wudaWeatherStationService.updateById(wudaWeatherStation);
       return Result.OK("编辑成功!");
   }

   /**
    *   通过id删除
    *
    * @param id
    * @return
    */
   @AutoLog(value = "气象站气象信息表-通过id删除")
   @ApiOperation(value="气象站气象信息表-通过id删除", notes="气象站气象信息表-通过id删除")
   @PostMapping(value = "/delete/{id}")
   public Result<String> delete(@PathVariable String id) {
       wudaWeatherStationService.removeById(id);
       return Result.OK("删除成功!");
   }



   /**
    * 通过id查询
    *
    * @param id
    * @return
    */
   //@AutoLog(value = "气象站气象信息表-通过id查询")
   @ApiOperation(value="气象站气象信息表-通过id查询", notes="气象站气象信息表-通过id查询")
   @GetMapping(value = "/queryById/{id}")
   public Result<WudaWeatherStation> queryById(@PathVariable String id) {
       WudaWeatherStation wudaWeatherStation = wudaWeatherStationService.getById(id);
       if(wudaWeatherStation==null) {
           return Result.error("未找到对应数据",null);
       }
       return Result.OK(wudaWeatherStation);
   }



}
